﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
	<title>hss.Content.Interlink.Client.SL5.TestApp</title>
	<style type="text/css">
		html, body {
			height: 100%;
			overflow: auto;
		}
		body {
			padding: 0;
			margin: 0;
		}
		#silverlightControlHost {
			height: 350px;
		}
		.container .column {
			position: relative;
			float: left;
			margin-top: 10px;
			margin-left: 10px;
		}
	</style>
	<script type="text/javascript" src="Silverlight.js"></script>
	<script type="text/javascript">

		var hss = null;

		// Called from Interlink to initialize the Javascript environment.
		function InitializeInterlink()
		{
			try
			{

				// Capture SL Control
				hss = document.getElementById("hssCtl");

				// ****************************************
				// Events
				// ****************************************
				
				// Occurs when the state of the Upload changes.
				hss.Content.Interlink.StateChanged = OnStateChanged;
				
				// Occurs when the progress percentage changes.
				hss.Content.Interlink.UploadProgressChanged = OnUploadProgressChanged;
				
				// Occurs when the upload completes.
				hss.Content.Interlink.UploadCompleted = OnUploadCompleted;
				
				// Occurs when a single file is added.
				hss.Content.Interlink.FileAdded = GenerateFileList;

				// Occurs when a single file is removed.
				hss.Content.Interlink.FileRemoved = GenerateFileList;

				// Occurs when a single file is changed.
				hss.Content.Interlink.FileChanged = GenerateFileList;

				// ****************************************
				// End Events
				// ****************************************

				// ****************************************
				// Configuration - All values below are their default values.
				// ****************************************
				
				// Gets or sets whether or not to overwrite existing files.
				//hss.Content.Interlink.AllowFileOverwrite = true;
				
				// Gets or sets whether or not the user can select multiple files.
				//hss.Content.Interlink.AllowMultiSelect = true;
				
				// Gets or sets whether or not once the first upload process completes, if the User can initiate a new upload.
				//hss.Content.Interlink.AllowNewUpload = true;
				
				// Gets or sets whether or not to begin uploading immediately after file selection.
				//hss.Content.Interlink.AutoUpload = false;
				
				// Gets or sets the configuration string to provide to the configurated IUploadClient client during intialization.
				//hss.Content.Interlink.ClientConfig = "UploadHandler"; // This default value is the app setting key to your server side file handler
				
				// Gets or sets a string defining the Type of the <see cref="IUploadClient"/> that will process the upload for a single file.
				//hss.Content.Interlink.ClientType = "HSS.Interlink.UploadClient";
				
				// Gets or sets a comment for display.
				//hss.Content.Interlink.Comment = "Select one or more files to be uploaded.";
				
				// Gets or sets the pipe delimited list of file extensions that are prohibited. Example: .exe|.mdb
				//hss.Content.Interlink.ExcludeFileExtension = ".exe|.mdb|.mde|.accdb|.accde";
				
				// Gets or sets a pipe delimeted string of allowed file extensions that can be uploaded.
				//hss.Content.Interlink.Filters = "All Files (*.*)|*.*";
				
				// Gets or sets the maximum number of concurrent files that can be uploaded at a time.
				//hss.Content.Interlink.MaximumConcurrency = "2";
				
				// Gets or sets the maximum size, in bytes, of any one file that can be uploaded.
				//hss.Content.Interlink.MaximumFileSize = "2147483647";
				
				// Gets or sets the text to be displayed when there are no files to upload.
				//hss.Content.Interlink.NoFilesText = "* Click the Browse button to select one or more files\r\n* Rightclick and click Browse to select one or more files\r\n* Drag the file(s) you want to upload into this area.";
				
				// Gets or sets the uri of a remote service to receive the file(s).
				//hss.Content.Interlink.ServiceUri = "/FileUpload.ashx";
				
				// Gets or sets a title for display.
				//hss.Content.Interlink.Title = "Upload Files";
				
				// Gets or sets the Uri of a DataTemplate resource to load that supports the Type defined in the UploadFileType property.
				//hss.Content.Interlink.UploadFileDataTemplate = "/HSS.Interlink;component/uploadfile.xaml";
				
				// Gets or sets the fully qualified name of the Type of the model that should contain an individual file for upload.
				//hss.Content.Interlink.UploadFileType = "HSS.Interlink.UploadFile";

				// ****************************************
				// End Configuration
				// ****************************************
				
			}
			catch (e)
			{
				alert(e);
			}
		}
		// Called from Interlink to collect optional metadata to send with a single file.
		// Is called for each file that is uploaded.
		function GetMetadata(fileName)
		{
			try
			{
				return fileName + " processed from Javascript!";
			}
			catch (e)
			{
				alert(e);
			}
		}

		// Event Handlers
		function OnStateChanged(s, e)
		{
			try
			{
				document.getElementById('UploadState').innerHTML = hss.Content.Interlink.StateFormatted;
			}
			catch (e)
			{
				alert(e);
			}
		}
		function OnUploadProgressChanged(s, e)
		{
			SetProgress(e.ProgressPercentage);
		}
		function OnUploadCompleted(s, e)
		{
			try
			{
				document.getElementById('UploadState').innerHTML = hss.Content.Interlink.StateFormatted;
			}
			catch (e)
			{
				alert(e);
			}
		}

		// Helper Methods
		function GenerateFileList()
		{
			var list = "<table><tr><td><b>File Name</b></td><td><b>State</b></td><td></td></tr>";
			var userFile;

			var i = 0;
			for (i = 0; i < hss.Content.Interlink.FileList.length; i++)
			{
				userFile = hss.Content.Interlink.FileList[i];
				list += "<tr><td>" + userFile.FileName + "&nbsp;&nbsp;</td><td>" + userFile.StateString + "</td><td></td></tr>";
			}

			list += "</table>"

			document.getElementById('FileList').innerHTML = list;

			UpdateTotal();
			UpdateUploaded();
			UpdatePercentage();
		}
		function UpdateTotal()
		{
			document.getElementById('TotalSelected').innerHTML = hss.Content.Interlink.TotalCount;
		}
		function UpdatePercentage()
		{
			SetProgress(hss.Content.Interlink.Percentage);
		}
		function UpdateUploaded()
		{
			document.getElementById('TotalUploaded').innerHTML = hss.Content.Interlink.FinishedCount;
		}
		function SetProgress(newvalue)
		{
			document.getElementById('TotalPercentage').innerHTML = newvalue + "%";
		}

		// Actions
		function UploadAsync()
		{
			if (hss != null)
			{
				hss.Content.Interlink.UploadAsync();
			}
		}
		function Reset()
		{
			if (hss != null)
			{
				hss.Content.Interlink.Reset();
			}
		}
		function RemoveAt(index)
		{
			if (hss != null)
			{
				hss.Content.Interlink.RemoveAt(index);
			}
		}
		function OnlyJPEGFiles()
		{
			hss.Content.Interlink.Filters = "Images (*.jpg) | *.jpg";
		}

		// Alerts
		function AlertUploadFiles()
		{
			if (hss != null)
			{
				alert("Uploaded Files: " + hss.Content.Interlink.FinishedCount);
			}
		}
		function AlertTotalFiles()
		{
			if (hss != null)
			{
				alert("Total Files: " + hss.Content.Interlink.TotalCount);
			}
		}
		function AlertProgressPercentage()
		{
			if (hss != null)
			{
				alert("Progress: " + hss.Content.Interlink.Percentage + "%");
			}
		}

		// Normal SL Error Handler
		function onSilverlightError(sender, args)
		{
			var appSource = "";
			if (sender != null && sender != 0)
			{
				appSource = sender.getHost().Source;
			}

			var errorType = args.ErrorType;
			var iErrorCode = args.ErrorCode;

			if (errorType == "ImageError" || errorType == "MediaError")
			{
				return;
			}

			var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

			errMsg += "Code: " + iErrorCode + "    \n";
			errMsg += "Category: " + errorType + "       \n";
			errMsg += "Message: " + args.ErrorMessage + "     \n";

			if (errorType == "ParserError")
			{
				errMsg += "File: " + args.xamlFile + "     \n";
				errMsg += "Line: " + args.lineNumber + "     \n";
				errMsg += "Position: " + args.charPosition + "     \n";
			}
			else if (errorType == "RuntimeError")
			{
				if (args.lineNumber != 0)
				{
					errMsg += "Line: " + args.lineNumber + "     \n";
					errMsg += "Position: " + args.charPosition + "     \n";
				}
				errMsg += "MethodName: " + args.methodName + "     \n";
			}

			throw new Error(errMsg);
		}
	</script>
</head>
<body>
	<div id="silverlightControlHost">
		<object id="hssCtl" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
			width="500" height="350">
			<param name="source" value="ClientBin/HSS.Interlink.Client.SL5.TestApp.xap" />
			<param name="onError" value="onSilverlightError" />
			<param name="background" value="white" />
			<param name="minRuntimeVersion" value="5.0.61118.0" />
			<param name="autoUpgrade" value="true" />
			<param name="initParams" value="mainpage=" />		  
			<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration: none">
				<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
					style="border-style: none" />
			</a>
		</object>
		<iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px;
			border: 0px"></iframe>
	</div>
	<br />
	<div>
		&nbsp;&nbsp;Status:&nbsp;<span id="UploadState">Ready</span>&nbsp;&nbsp;|&nbsp;&nbsp;<span id="TotalUploaded">0</span>
		of <span id="TotalSelected">0</span> file uploaded.&nbsp;&nbsp;<span id="TotalPercentage"></span>
	</div>
	<div class="container">
		<div class="column">
			<button onclick="UploadAsync();">
				Upload</button>
		</div>
		<div class="column">
			<button onclick="Reset();">
				Reset</button>
		</div>
		<div class="column">
			<button onclick="RemoveAt(0);">
				Remove 1st file</button>
		</div>
		<div class="column">
			<button onclick="RemoveAt(1);">
				Remove 2nd file</button>
		</div>
		<div style="clear: both" />
	</div>
	<div class="container">
		<div class="column">
			<button onclick="AlertTotalFiles()">
				Alert Count</button></div>
		<div class="column">
			<button onclick="AlertUploadFiles()">
				Alert Uploaded</button></div>
		<div class="column">
			<button onclick="AlertProgressPercentage();">
				Alert Percentage</button></div>
		<div class="column">
			<button onclick="OnlyJPEGFiles();">
				Set Filters = JPEG Files Only</button></div>
		<div style="clear: both" />
	</div>
	<hr />
	<div id="FileList">
	</div>
	<hr />
	<br />
	<br />
</body>
</html>
